package org.example.new_hbps_backend_reconstruction.handler;

import org.springframework.web.socket.WebSocketSession;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 丁利军
 * @date 2025年10月11日 21:50
 * @description TODO: 描述
 */

public final class WebSocketSessionHolder {
    private static final Map<String, WebSocketSession> USER_SESSION_MAP = new ConcurrentHashMap();

    private WebSocketSessionHolder() {
    }

    public static void addSession(Object sessionKey, WebSocketSession session) {
        USER_SESSION_MAP.put(sessionKey.toString(), session);
    }

    public static void removeSession(Object sessionKey) {
        USER_SESSION_MAP.remove(sessionKey.toString());
    }

    public static WebSocketSession getSession(Object sessionKey) {
        return (WebSocketSession)USER_SESSION_MAP.get(sessionKey.toString());
    }

    public static Collection<WebSocketSession> getSessions() {
        return USER_SESSION_MAP.values();
    }

    public static Set<String> getSessionKeys() {
        return USER_SESSION_MAP.keySet();
    }
}

